package com.trip.driver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trip.common.po.CarInfo;
import com.trip.common.vo.MyResultMap;
import com.trip.common.vo.Result;
import com.trip.driver.mapper.CarInfoMapper;
import com.trip.driver.service.CarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hr
 * @since 2024-09-05
 */
@Service
public class CarInfoServiceImpl extends ServiceImpl<CarInfoMapper, CarInfo> implements CarInfoService {

    @Autowired
    private CarInfoMapper carInfoMapper;

    @Override
    public Result regCarInfo(CarInfo carInfo) {
        int i = carInfoMapper.regCarInfo(carInfo);
        if (i > 0){
            return Result.ok("申请已提交");
        }else {
            return Result.error("申请提交失败");
        }
    }

    @Override
    public Result getCarInfoByDriver(String driver_id) {
        List<CarInfo> carInfoByDriver = carInfoMapper.getCarInfoByDriver(driver_id);
        if (carInfoByDriver.size() > 0){
            HashMap<String, Object> myResultMap = MyResultMap.getMyResultMap();
            myResultMap.put("data",carInfoByDriver);
            return Result.ok("获取信息成功",myResultMap);
        }else{
            return Result.error("当前无申请记录");
        }
    }
}
